package com.ruoyi.cscec.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.cscec.domain.SurveyOrder;
import com.ruoyi.cscec.service.ISurveyOrderService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 调查工单Controller
 *
 * @author ruoyi
 * @date 2021-09-27
 */
@RestController
@RequestMapping("/surveyOrder")
public class SurveyOrderController extends BaseController
{
    @Autowired
    private ISurveyOrderService surveyOrderService;

    /**
     * 查询调查工单列表
     */
    @PreAuthorize(hasPermi = "surveyOrder:cscec:list")
    @GetMapping("/list")
    public TableDataInfo list(SurveyOrder surveyOrder)
    {
        startPage();
        List<SurveyOrder> list = surveyOrderService.selectSurveyOrderList(surveyOrder);
        return getDataTable(list);
    }

    /**
     * 导出调查工单列表
     */
    @PreAuthorize(hasPermi = "surveyOrder:cscec:export")
    @Log(title = "调查工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurveyOrder surveyOrder) throws IOException
    {
        List<SurveyOrder> list = surveyOrderService.selectSurveyOrderList(surveyOrder);
        ExcelUtil<SurveyOrder> util = new ExcelUtil<SurveyOrder>(SurveyOrder.class);
        util.exportExcel(response, list, "调查工单数据");
    }

    /**
     * 获取调查工单详细信息
     */
    @PreAuthorize(hasPermi = "surveyOrder:cscec:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(surveyOrderService.selectSurveyOrderById(id));
    }

    /**
     * 新增调查工单
     */
    @PreAuthorize(hasPermi = "surveyOrder:cscec:add")
    @Log(title = "调查工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveyOrder surveyOrder)
    {
        return toAjax(surveyOrderService.insertSurveyOrder(surveyOrder));
    }

    /**
     * 修改调查工单
     */
    @PreAuthorize(hasPermi = "surveyOrder:cscec:edit")
    @Log(title = "调查工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveyOrder surveyOrder)
    {
        return toAjax(surveyOrderService.updateSurveyOrder(surveyOrder));
    }

    /**
     * 删除调查工单
     */
    @PreAuthorize(hasPermi = "surveyOrder:cscec:remove")
    @Log(title = "调查工单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surveyOrderService.deleteSurveyOrderByIds(ids));
    }
}
